//
//  IconScrollerBarView.m
//  IconMaster
//
//  Created by mac on 2017/9/12.
//  Copyright © 2017年 yangweiwei. All rights reserved.
//

#import "IconScrollerBarView.h"

#import "HorizontalMenuView.h"
@interface IconScrollerBarView()<IconScrollerViewDelegate, HorizontalMenuProtocol>
@property (nonatomic, strong) UIImageView *textImgView;

@property (nonatomic, strong) HorizontalMenuView *hormenView;
@property (nonatomic, strong) UIButton *okButton;
@property (nonatomic, strong) UIImage *selectedImg;
@property (nonatomic, assign) NSInteger clickButtonIndex;
@end

@implementation IconScrollerBarView


- (void)dealWithImgArr:(NSArray *)contentArr{
// [self setNeedsLayout];
    self.frame = CGRectMake(0, KHeight - 230, KWidth, 230);
    [self layoutIfNeeded];
    [_iconScrollerView removeFromSuperview];
    _iconScrollerView = [[IconScrollerView alloc] init];
    _iconScrollerView.frame = CGRectMake(0, CGRectGetMaxY(self.textImgView.frame) + 8, KWidth, 80);
    [self addSubview:self.iconScrollerView];
    _iconScrollerView.delegate = self;
    self.iconScrollerView.contentArr = contentArr;
    //    self.iconScrollerView.backgroundColor = [UIColor grayColor];
    
    [self.iconScrollerView initSubViewsInArr];
//    self.iconScrollerView.sd_layout.leftSpaceToView(self, 0).rightSpaceToView(self, 0).heightIs(80).centerYEqualToView(self);
    
    
}

- (void)creatSeledImgBackGroundView{
   
    
    
    [self addSubview:self.okButton];
    self.okButton.sd_layout.bottomSpaceToView(self, 8).centerXEqualToView(self).widthIs(80).heightIs(80);
    
    UIImage *imag = [UIImage imageNamed:@"Bbackground"];
    _textImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Bbackground"]];
    _textImgView.frame = CGRectMake((KWidth - imag.size.width) /2, 8, imag.size.width, imag.size.height);
    _textImgView.userInteractionEnabled = YES;
    [self addSubview:self.textImgView];
//    self.textImgView.sd_layout.centerXEqualToView(self).topSpaceToView(self, 8).widthIs(imag.size.width).heightIs(imag.size.height).bottomSpaceToView(self.iconScrollerView, 8);
    
    NSArray *menarr= @[@"背景",@"边框",@"装饰",@"文字"];
    
   
    
     _hormenView = [[HorizontalMenuView alloc] initWithFrame:CGRectMake(0, 0, _textImgView.frame.size.width, _textImgView.height)];
//    self.hormenView.sd_layout.leftSpaceToView(self.textImgView, 0).rightSpaceToView(self.textImgView, 0).topSpaceToView(self.textImgView, 0).bottomSpaceToView(self.textImgView, 0);
    _hormenView.delegate = self;
    [self.hormenView setNameWithArray:menarr];
     [self.textImgView addSubview:self.hormenView];
    
    
    
    //    if (contentArr) {
//        self.iconScrollerView.sd_layout.leftSpaceToView(self, 0).rightSpaceToView(self, 0).bottomSpaceToView(self.okButton, 8).heightIs(60);
//    }

    
    
   }

#pragma mark --textImgView

//- (UIImageView *)textImgView{
//
//    if (!_textImgView) {
//        _textImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Bbackground"]];
//        _textImgView.userInteractionEnabled = YES;
//    }
//    return _textImgView;
//}
//
//- (HorizontalMenuView *)hormenView{
//
//    if (!_hormenView) {
//        _hormenView = [[HorizontalMenuView alloc] init];
//    }
//    return _hormenView;
//}
- (void)getTag:(NSInteger)tag{
self.clickButtonIndex = tag;
    switch (tag) {
        case 0:
            //背景
            
            if ([self.deleagte respondsToSelector:@selector(buttonClickWithFourSeleted:)]) {
                [self.deleagte buttonClickWithFourSeleted:tag];
            }

            break;
        case 1:
            //边框
            if ([self.deleagte respondsToSelector:@selector(buttonClickWithFourSeleted:)]) {
                [self.deleagte buttonClickWithFourSeleted:tag];
            }

            break;
        case 2:
            //装饰
            if ([self.deleagte respondsToSelector:@selector(buttonClickWithFourSeleted:)]) {
                [self.deleagte buttonClickWithFourSeleted:tag];
            }

            break;
        case 3:
            //文字
            if ([self.deleagte respondsToSelector:@selector(buttonClickWithFourSeleted:)]) {
                [self.deleagte buttonClickWithFourSeleted:tag];
            }

            break;
        default:
            break;
    }
}
#pragma mark --OKButton
- (UIButton *)okButton{
    if (!_okButton) {
        _okButton = [[UIButton alloc] init];
        [_okButton setImage:[UIImage imageNamed:@"beautifyok_ch"] forState:Normal];
        [_okButton addTarget:self action:@selector(okbuttonAction) forControlEvents:TouchUPInside];
    }
    return _okButton;
}
- (void)okbuttonAction{

    if ([self.deleagte respondsToSelector:@selector(okbuttonAction:)]) {
        [self.deleagte okbuttonAction:self.selectedImg];
    }
}
#pragma mark --IconScrollerView
//- (IconScrollerView *)iconScrollerView{
//
//    if (!_iconScrollerView) {
//        _iconScrollerView = [[IconScrollerView alloc] init];
//        _iconScrollerView.delegate = self;
//    }
//    return _iconScrollerView;
//}

- (void)buttonImage:(UIImage *)image{

    NSLog(@"%@", image);
    if (self.clickButtonIndex !=3) {
        if ([self.deleagte respondsToSelector:@selector(buttonSelected:andTypeIndex:)]) {
            [self.deleagte buttonSelected:image andTypeIndex:self.clickButtonIndex];
        }
    }
    
}

- (void)butonMore{
//更多
     if (self.clickButtonIndex !=3) {
       if ([self.deleagte respondsToSelector:@selector(buttonMoreWithBar:)]) {
        [self.deleagte buttonMoreWithBar:self.clickButtonIndex];
       }
     }
}
@end
